package leetcode20211005;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-10-05
 * Time: 11:01
 */
public class MaxSum {
    public static void main(String[] args) {

    }
}

class Solution {
    public int maxSubArray(int[] nums) {
        int max = nums[0];
        int former = 0;
        int cur = nums[0];
        for(int num : nums){
            cur = num;//当前指向的数字
            if(former > 0) cur += former;
            former = cur;
            if(cur > max) max = cur;
        }

        return max;

    }
}
